home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 419_01 / odmg10 / lib / odmg / test / main.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-28  |  2.5 KB  |  136 lines

  1. /*******************************<+>***************************
  2.  **                             DTA
  3.  *************************************************************
  4.  **
  5.  **  $Id: main.C,v 1.8 1994/03/01 23:01:30 dta Exp $
  6.  **
  7.  **  $Source: /cvs/lib/odmg/test/main.C,v $
  8.  **
  9.  **  What @(#):
  10.  **
  11.  **  Author: Dale T. Anderson
  12.  **
  13.  *******************************<+>***************************/
  14.  
  15. #include "Test.h"
  16.  
  17. #include <Odmg/List.h>
  18. #include <Odmg/Array.h>
  19. #include <Odmg/Bag.h>
  20. #include <Odmg/Set.h>
  21.  
  22. int verbose = 0;
  23.  
  24. CTest::CTest (const int val)
  25. {
  26.     //printf ("Construct CTest %d %x\n", val, this);
  27.     m_val = val;
  28. }
  29.  
  30. CTest::~CTest ()
  31. {
  32.     //printf ("Destroy CTest %d %x\n", m_val, this);
  33. }
  34.  
  35. void CTest::Print ()
  36. {
  37.     print ("%d", m_val);
  38. }
  39.  
  40. static void TestSet (Set <CTest> &set)
  41. {
  42.     PrintInfo ("Set", set);
  43. }
  44.  
  45. static void TestBag (Bag <CTest> &bag)
  46. {
  47.     PrintInfo ("Bag", bag);
  48. }
  49.  
  50. static void TestList (List <CTest> &list)
  51. {
  52.     PrintInfo ("List", list);
  53. }
  54.  
  55. static void TestArray (Varray <CTest> &array)
  56. {
  57.     PrintInfo ("Array", array);
  58. }
  59.  
  60. static void DeleteRef (Ref <ListNode <CTest> > ref)
  61. {
  62.     delete (ListNode <CTest> *) ref;
  63. }
  64.  
  65. static void TestListNode ()
  66. {
  67.     const int count = 10;
  68.  
  69.     ListNode <CTest> list;
  70.  
  71.     for (int i = 0; i < count; i++)
  72.     list.insert_node (new ListNode <CTest> (new CTest (i)));
  73.  
  74.     for (i = 0; i < count; i++) {
  75.     delete (CTest *)(list.get_next_node ()->get_ref ());
  76.     DeleteRef (list.get_next_node ());
  77.     }
  78.  
  79.     for (i = 0; i < count; i++)
  80.     list.append_node (new ListNode <CTest> (new CTest (i)));
  81.  
  82.     for (i = 0; i < count; i++) {
  83.     delete (CTest *)(list.get_next_node ()->get_ref ());
  84.     DeleteRef (list.get_next_node ());
  85.     }
  86. }
  87.  
  88. int main (int argc, char **argv)
  89. {
  90.     extern int optopt;
  91.     int err = 0;
  92.     int c;
  93.  
  94.     while ((c = getopt (argc, argv, "v")) != -1) {
  95.     switch (c) {
  96.         case 'v':
  97.         verbose++;
  98.         break;
  99.         case ':':
  100.         fprintf (stderr, "Option -%c requires an argument\n", optopt);
  101.         err++;
  102.         break;
  103.         case '?':
  104.         fprintf (stderr, "Unrecognized option: - %c\n", optopt);
  105.         err++;
  106.         break;
  107.     }
  108.     }
  109.  
  110.     if (err) {
  111.     fprintf (stderr, "Life is tough, life is tougher if you dont use -v\n");
  112.     exit (1);
  113.     }
  114.  
  115.     TestListNode ();
  116.  
  117.     Varray <CTest> array (0);
  118.     TestCollection ("Array", array);
  119.     TestArray (array);
  120.  
  121.     List <CTest> list;
  122.     TestCollection ("List", list);
  123.     TestList (list);
  124.  
  125.     Bag <CTest> bag;
  126.     TestCollection ("Bag", bag);
  127.     TestBag (bag);
  128.  
  129.     Set <CTest> set;
  130.     TestCollection ("Set", set);
  131.     TestSet (set);
  132.  
  133.     return 0;
  134. }
  135.  
  136.